<?php
ob_start();
date_default_timezone_set("PRC");
define("PHPOK_SET", TRUE);
define("LANGUAGE_ID",1);
define("LANGUAGE_SIGN",'zh');
$start_time = explode(" ",microtime());
$start_time = $start_time[0] + $start_time[1];
define("START_TIME",$start_time);
unset($start_time);
error_reporting(E_ERROR | E_WARNING | E_PARSE);
#error_reporting(E_ALL);
require_once("include/360_safe3.php");
require_once("config.php");

#[加载字符串处理类]
require_once("class/string.class.php");
$STR = new QG_C_STRING(false,false,false);

$magic_quotes_gpc = get_magic_quotes_gpc();
@extract($STR->format($_POST));
@extract($STR->format($_GET));
if(!$magic_quotes_gpc)
{
	$_FILES = $STR->format($_FILES);
}

session_start();
#[加载数据库]
require_once("class/mysql.db.class.php");
$DB = new qgSQL($prefix,$dbHost,$dbData,$dbUser,$dbPass,false);

#[加载管理语言包]
require_once("class/lang.class.php");
$LNG = new QG_C_LANG($DB,$prefix);
$langs = $LNG->lang();

require_once("class/file.class.php");
$FS = new files();
require_once("include/overall.func.php");
require_once("include/global.func.php");

#[站点路径]
$siteurlnew = site_uri();
define("SITE_URI",$siteurlnew);
define("SITE_URI_FUL","http://".$_SERVER["HTTP_HOST"].$siteurlnew);

#[加载网站常规选项]
if(!file_exists("data/system_".LANGUAGE_ID.".php"))
{
	echo "Not Set System.";
	exit;

}
include_once("data/system_".LANGUAGE_ID.".php");

#[获取网站设置的网址]
$icp="<a href='http://www.miibeian.gov.cn/' target='_blank'>".$icp."</a>";
$siteurl = $system["siteurl"];
if(!$siteurl)
{
	$siteurl = "./";
}
if(substr($siteurl,-1) != "/")
{
	$siteurl .= "/";
}

#[计算当前时间]
$system_time = $system_now = mktime(gmdate("H")+$system["timezone"],gmdate("i")+$system["timerevise"],gmdate("s"),gmdate("m"),gmdate("d"),gmdate("Y"));
if($system["icp"]){
	$icp= "<a href='http://www.miibeian.gov.cn/' target='_blank'>".$system["icp"]."</a>";	
}

#[判断是否属手机]
function is_mobile() {
	$user_agent = $_SERVER['HTTP_USER_AGENT'];
	$mobile_agents = Array("240x320","acer","acoon","acs-","abacho","ahong","airness","alcatel","amoi","android","anywhereyougo.com","applewebkit/525","applewebkit/532","asus","audio","au-mic","avantogo","becker","benq","bilbo","bird","blackberry","blazer","bleu","cdm-","compal","coolpad","danger","dbtel","dopod","elaine","eric","etouch","fly ","fly_","fly-","go.web","goodaccess","gradiente","grundig","haier","hedy","hitachi","htc","huawei","hutchison","inno","ipad","ipaq","ipod","jbrowser","kddi","kgt","kwc","lenovo","lg ","lg2","lg3","lg4","lg5","lg7","lg8","lg9","lg-","lge-","lge9","longcos","maemo","mercator","meridian","micromax","midp","mini","mitsu","mmm","mmp","mobi","mot-","moto","nec-","netfront","newgen","nexian","nf-browser","nintendo","nitro","nokia","nook","novarra","obigo","palm","panasonic","pantech","philips","phone","pg-","playstation","pocket","pt-","qc-","qtek","rover","sagem","sama","samu","sanyo","samsung","sch-","scooter","sec-","sendo","sgh-","sharp","siemens","sie-","softbank","sony","spice","sprint","spv","symbian","tablet","talkabout","tcl-","teleca","telit","tianyu","tim-","toshiba","tsm","up.browser","utec","utstar","verykool","virgin","vk-","voda","voxtel","vx","wap","wellco","wig browser","wii","windows ce","wireless","xda","xde","zte");
	$is_mobile = false;
	foreach ($mobile_agents as $device) {
		if (stristr($user_agent, $device)) {
			$is_mobile = true;
			break;
		}
	}
	return $is_mobile;
}
$mob = is_mobile();

#[判断安卓苹果]
function is_ios() {
	$user_agent = $_SERVER['HTTP_USER_AGENT'];
	$mobile_agents = Array("ipad","ipaq","ipod","ios","iphone");
	$is_ios = false;
	foreach ($mobile_agents as $device) {
		if (stristr($user_agent, $device)) {
			$is_ios = true;
			break;
		}
	}
	return $is_ios;
}
$ifios = is_ios();

/*if($template)
{
	header("Location: ".SITE_URI);
}*/

#[新建缓存文件夹]
if(!file_exists("data"))
{
	mkdir("data",0777,true);
}
if(!file_exists("data/phpok_tplc"))
{
	mkdir("data/phpok_tplc",0777,true);
}
if(!file_exists("data/phpok_tplc/m_"))
{
	mkdir("data/phpok_tplc/m_",0777,true);
}
if(!file_exists("data/cache"))
{
	mkdir("data/cache",0777,true);
}

#[获得域名]
$trueurl = getServerName();

#[加载模板类]
require_once("class/tpl.class.php");

if($mob)
{
	if(file_exists("templates/zh/m_default") || file_exists("templates/zh/m_en"))
	{
		$mobli="m_";
	}
}

#[是否启用共享模板]
if($iftempshare)
{
	$tempshare = "default";
}
else
{
	$tempshare = TPL_FOLDER;
}
$set = array
(
	"tplid"=>TemplateID,
	"tpldir"=>"templates/".LANGUAGE_SIGN."/".$mobli."".$tempshare,
	"cache"=>"data/phpok_tplc/".$mobli,
	"phpdir"=>"",
	"ext"=>"htm",
	"autorefresh"=>true,
	"autoimg"=>true
);

$TPL = new QG_C_TEMPLATE($set);
$TPL->set($set["tplid"],"tplid");
$TPL->set($set["tpldir"],"tpldir");
$TPL->set($set["cache"],"cache");
$TPL->set($set["phpdir"],"phpdir");
define("NewTemplate",$set["tpldir"]);
unset($set);

#[模板文件夹名称]
$bi = getfolder(TemplateID);
if(!$bi)
{
	$bistr = "cn";
}
else
{
	$bistr = str_replace(array("_"),array(""),$bi);
}
define("BI",$bistr);

#[加载页面类]
require_once("class/page.class.php");
$PA = new pageclass($DB,$prefix,$bi);

#[防SQL注入]
$fsql_arr = array("select","insert","update","and","or","where","into","limit","order");
$fsql0 = $_GET;
if($fsql0)
{
	foreach($fsql0 AS $key=>$value)
	{
		$value = strtolower($value);
		$value = preg_replace('# #','',$value);
		$key = strtolower($key);
		$key = preg_replace('# #','',$key);
		$fsql[$key] = $value;
	}
	foreach($fsql AS $key=>$value)
	{
		if(in_array($key,$fsql_arr) || in_array($value,$fsql_arr))
		{
			Error("Error");
		}
	}
	unset($fsql0,$fsql);
}
unset($fsql_arr);

#[判断网站状态]
if(file_exists("data/site.lock.php"))
{
	$status_json = $FS->qgRead("data/site.lock.php");
	$status_arr = json_decode($status_json);
	foreach($status_arr AS $key=>$value)
	{
		$status_arr2[$key] = $value;
	}
	if($status_arr2["content"])
	{
		#[如果有跳转链接]
		if($status_arr2["link"])
		{
			Error(base64_decode($status_arr2["content"]),$status_arr2["link"]);
		}
		else
		{
			Error(base64_decode($status_arr2["content"]));
		}
	}
	else
	{
		Error("Close...");
	}
}



$hangye_cate=$DB->qgGetAll("SELECT * FROM ".$prefix."hangye_cate WHERE status=1 ORDER BY id ASC ");

require_once("include/qgmod.func.php");

if($_SESSION["qg_sys_user"])
{
	$USER_STATUS = true;
}
else
{
	$USER_STATUS = false;
}
define("USER_STATUS",$USER_STATUS);
unset($USER_STATUS);

$system["description"]=$system["description".$bi];
$system["keywords"]=$system["keywords".$bi];

#[计算当前页的网址]
$PHP_SELL_QUERY_STRING = basename($_SERVER["PHP_SELF"]);
if($_SERVER["QUERY_STRING"])
{
	$PHP_SELL_QUERY_STRING .= "?".$_SERVER["QUERY_STRING"];
}
?>